package com.zxjbyte.yiyi.framework.operatelog.event;

import com.zxjbyte.yiyi.module.system.api.log.OperateLogApi;
import lombok.RequiredArgsConstructor;
import org.springframework.context.event.EventListener;
import org.springframework.core.annotation.Order;

/**
 *
 * @Author zhangxingjia
 * @Date 2023/3/17 15:00
 * @Version: 1.0
 */
@RequiredArgsConstructor
public class OperateLogListener {

    private final OperateLogApi operateLogApi;

    @Order
    @EventListener(value = OperateLogAddEvent.class)
    public void addOperateLog(OperateLogAddEvent event) {
        // Spring Framework的事件机制是同步的，即事件发布和处理是在同一个线程中完成的, 所以这里使用线程池异步保存操作日志
        operateLogApi.asyncAdd(event.getAddDto());
    }
}
